package models

import (
	"time"
)

// SecurityEvent 安全事件模型
type SecurityEvent struct {
	ID              uint      `gorm:"primaryKey" json:"id"`
	EventID         string    `gorm:"size:50;not null;uniqueIndex" json:"event_id"`
	Title           string    `gorm:"size:200;not null" json:"title"`
	Type            string    `gorm:"size:50;not null;index" json:"type"` // login, withdrawal, payment, system
	Severity        string    `gorm:"size:20;not null" json:"severity"`  // high, medium, low, info
	Description     string    `gorm:"type:text" json:"description"`
	Timestamp       string    `gorm:"size:50;not null;index" json:"timestamp"`
	IpAddress       string    `gorm:"size:50" json:"ip_address"`
	Location        string    `gorm:"size:200" json:"location"`
	UserID          uint      `gorm:"index" json:"user_id"`
	Username        string    `gorm:"size:50" json:"username"`
	AffectedScope   string    `gorm:"size:100" json:"affected_scope"`
	Status          string    `gorm:"size:20;not null;index" json:"status"` // pending, handled, ignored
	SuggestedAction string    `gorm:"size:500" json:"suggested_action"`
	ExtraData       string    `gorm:"type:text" json:"extra_data"` // JSON格式存储额外数据
	Handler         string    `gorm:"size:50" json:"handler"`
	Remark          string    `gorm:"size:500" json:"remark"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

// TableName 指定表名
func (SecurityEvent) TableName() string {
	return "security_events"
}

// SecuritySetting 安全设置模型
type SecuritySetting struct {
	ID                        uint      `gorm:"primaryKey" json:"id"`
	RemoteLoginVerify         bool      `gorm:"not null" json:"remote_login_verify"`
	LoginFailureLock          bool      `gorm:"not null" json:"login_failure_lock"`
	LargeTransactionVerify    bool      `gorm:"not null" json:"large_transaction_verify"`
	AbnormalTransactionControl bool     `gorm:"not null" json:"abnormal_transaction_control"`
	DailyTransactionLimit     string    `gorm:"size:20" json:"daily_transaction_limit"`
	SensitiveOperationLog     bool      `gorm:"not null" json:"sensitive_operation_log"`
	RegularSecurityScan       bool      `gorm:"not null" json:"regular_security_scan"`
	UpdateTime                string    `gorm:"size:50" json:"update_time"`
	CreatedAt                 time.Time `json:"created_at"`
	UpdatedAt                 time.Time `json:"updated_at"`
}

// TableName 指定表名
func (SecuritySetting) TableName() string {
	return "security_settings"
}

// SecurityStatus 安全状态概览模型
type SecurityStatus struct {
	ID               uint      `gorm:"primaryKey" json:"id"`
	SecurityScore    int       `gorm:"not null" json:"security_score"`
	TodayEvents      int       `gorm:"not null" json:"today_events"`
	RiskUsers        int       `gorm:"not null" json:"risk_users"`
	RiskTransactions int       `gorm:"not null" json:"risk_transactions"`
	IncomeRate       float64   `gorm:"not null" json:"income_rate"`
	EventTrend       string    `gorm:"size:20" json:"event_trend"` // increasing, decreasing, stable
	LastScanTime     string    `gorm:"size:50" json:"last_scan_time"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

// TableName 指定表名
func (SecurityStatus) TableName() string {
	return "security_status"
}

// UserSecurityInfo 用户安全信息模型
type UserSecurityInfo struct {
	ID                uint      `gorm:"primaryKey" json:"id"`
	UserID            uint      `gorm:"not null;uniqueIndex" json:"user_id"`
	Username          string    `gorm:"size:50" json:"username"`
	RiskScore         int       `gorm:"not null" json:"risk_score"`
	LastLoginTime     string    `gorm:"size:50" json:"last_login_time"`
	LastLoginIp       string    `gorm:"size:50" json:"last_login_ip"`
	LastLoginLocation string    `gorm:"size:200" json:"last_login_location"`
	IsVerified        bool      `gorm:"not null" json:"is_verified"`
	HasBindPhone      bool      `gorm:"not null" json:"has_bind_phone"`
	HasBindEmail      bool      `gorm:"not null" json:"has_bind_email"`
	RiskLevel         string    `gorm:"size:20" json:"risk_level"` // high, medium, low
	CreatedAt         time.Time `json:"created_at"`
	UpdatedAt         time.Time `json:"updated_at"`
}

// TableName 指定表名
func (UserSecurityInfo) TableName() string {
	return "user_security_info"
}